package com.blqy.fr.template.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blqy.fr.model.template.TemplateTag;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface TemplateTagMapper extends BaseMapper<TemplateTag> {

    @Select("SELECT * FROM template_tag WHERE id = #{id} AND is_deleted = 0")
    TemplateTag selectById(Long id);

    @Select("""
        SELECT 
            tt.* 
        FROM 
            template_tag tt
        INNER JOIN 
            template_tag_relation ttr 
        ON 
            tt.id = ttr.template_tag_id
        WHERE 
            ttr.template_id = #{templateId} 
          AND tt.template_tag = #{tagName}
          AND tt.is_deleted = 0
          AND ttr.is_deleted = 0
        """)
    TemplateTag selectByTemplateNameAndTag(@Param("templateId") Long templateId, @Param("tagName") String tagName);

    @Select("""
        SELECT 
            id
        FROM 
            template_tag
        WHERE 
            template_tag = #{key}
        """)
    Long selectParentId(String key);
}
